function Animate(obj) {
	if (obj.x === undefined) { obj.x = 0; }
	if (obj.y === undefined) { obj.x = 0; }
	if (obj.frames === undefined) { obj.frames = 1; }
	if (obj.currentFrame === undefined) { obj.currentFrame = 0; }
	if (obj.fps === undefined) { obj.fps = 24; }
	if (obj.frameTime === undefined) { obj.frameTime = 0; }
	if (obj.playOnce === undefined) { obj.playOnce = false; }
	if (obj.scaleX === undefined) { obj.scaleX = 1; }
	if (obj.scaleY === undefined) { obj.scaleY = 1; }

	this.img = obj.img;
	this.x = obj.x;
	this.y = obj.y;
	this.frames = obj.frames;
	this.currentFrame = obj.currentFrame;
	this.fps = obj.fps;
	this.frameTime = obj.frameTime;
	this.playOnce = obj.playOnce;

	this.frameWidth = this.img.width/this.frames;
	this.frameHeight = this.img.height;
	this.scaleX = obj.scaleX;
	this.scaleY = obj.scaleY;

	//console.log(this.currentFrame);
}

Animate.prototype.draw = function(ctx) {
	//console.log(this.img+"..."+this.frames+"..."+this.currentFrame+"..."+this.fps+"..."+this.frameWidth+"...."+this.frameHeight+"..."+this.x+"..."+this.y+"..."+this.scaleX+"..."+this.scaleY);
	ctx.drawImage(this.img,this.currentFrame*this.frameWidth,0,this.frameWidth,this.frameHeight,this.x,this.y,this.frameWidth*this.scaleX,this.frameHeight*this.scaleY);
}

Animate.prototype.enterFrame = function(dt) {
	this.frameTime += dt;
	
	if (this.fps != 0)
	{
		console.log(this.frameTime+"....."+this.currentFrame);
		while (this.frameTime > 1/this.fps)
		{
			console.log(this.frameTime+"....."+this.currentFrame);
			this.frameTime -= 1/this.fps;
			this.currentFrame = (this.currentFrame + 1) % this.frames;
			if (this.currentFrame == 0 && this.playOnce)
			{
//				changeState();
				break;
			}
		}
	}
}